package com.woniu.controller;

import com.woniu.entity.BillingRule;
import com.woniu.service.BillingRuleService;
import com.woniu.vo.BillingRuleVO;
import com.woniu.util.ResponseData;
import com.woniu.util.ResponseEnum;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/billingRule")
public class BillingRuleController {
    @Resource
    private BillingRuleService billingRuleService;

    @GetMapping("/list")
    public ResponseData<?> getBillingRuleList(
            @RequestParam(required = false) String keyword,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        List<BillingRuleVO> rules = billingRuleService.getBillingRuleList(keyword, pageNum, pageSize);
        return ResponseData.ok(rules);
    }

    @PostMapping("/add")
    public ResponseData<?> addBillingRule(@RequestBody BillingRule billingRule) {
        boolean success = billingRuleService.addBillingRule(billingRule);
        return success ? ResponseData.ok() : ResponseData.fail(ResponseEnum.FAIL);
    }

    @DeleteMapping("/{id}")
    public ResponseData<?> deleteBillingRule(@PathVariable("id") Long id) {
        boolean success = billingRuleService.deleteBillingRule(id);
        return success ? ResponseData.ok() : ResponseData.fail(ResponseEnum.FAIL);
    }

    @PostMapping("/update")
    public ResponseData<?> updateBillingRule(@RequestBody BillingRule billingRule) {
        boolean success = billingRuleService.updateBillingRule(billingRule);
        return success ? ResponseData.ok() : ResponseData.fail(ResponseEnum.FAIL);
    }
} 